<?php

namespace App\Console\Commands\Cruise;

use App\Models\Common\ConfigModel;
use App\Models\Cruise\CruiseCheckAlbumModel;
use Illuminate\Console\Command;

class CruiseCheckDeleteExpired extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'cruise:cruise_check_delete_expired';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '删除过期的稽核相册资源';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $expiredTime = configModel::getCruiseAlbumExpiredTime();//获取稽核巡检图库保存时间（单位：秒）
        CruiseCheckAlbumModel::query()
            ->where('status', CruiseCheckAlbumModel::STATUS_UNUSED)
            ->where('createdAt', '<', time() - $expiredTime)
            ->update([
                'isDeleted' => 1
            ]);
    }
}
